package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.MarketComment;
import com.cskaoyan.bean.comment.bo.ListCommentWxBo;
import com.cskaoyan.bean.comment.vo.CommentWxListVo;
import com.cskaoyan.bean.comment.vo.CountVo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/comment")
public class CommentVXController {

    @Autowired
    CommentService commentService;

    @RequestMapping("list")
    public BaseRespVo listAllComment(ListCommentWxBo listCommentWxBo) {
        CommonData<CommentWxListVo> baseRespVoCommonData = commentService.listAllCommentWx(listCommentWxBo);
        BaseRespVo baseRespVo = BaseRespVo.ok(baseRespVoCommonData);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;

    }

    @RequestMapping("count")
    public BaseRespVo countComment(MarketComment marketComment) {
        CountVo countVo = commentService.queryCommentCount(marketComment);
        BaseRespVo baseRespVo = BaseRespVo.ok(countVo);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }

    @RequestMapping("post")
    public BaseRespVo postComment(@RequestBody  MarketComment marketComment) {
        commentService.insertComment(marketComment);

        //返回的值
        MarketComment marketComment1 = new MarketComment();
        marketComment1.setContent(marketComment.getContent());
        marketComment1.setPicUrls(marketComment.getPicUrls());
        marketComment1.setStar(marketComment.getStar());
        marketComment1.setType(marketComment.getType());
        marketComment1.setValueId(marketComment.getValueId());
        marketComment1.setHasPicture(marketComment.getHasPicture());
        BaseRespVo baseRespVo = BaseRespVo.ok(marketComment1);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }
}

